package cn.me.alphamq.broker.model.tx;

import cn.me.alphamq.common.entity.req.PushTxMsgReq;
import io.netty.channel.ChannelHandlerContext;

/**
 * 事务消息的模型
 *
 * @author f
 */
public class TxMsgModel {

    /**
     * 消息的主题
     */
    private final String topic;

    /**
     * 放入消息的队列 id，默认值是 -1，如果没有传递，则会在写入数据时默认写到 0 号队列
     */
    private final int queueId;

    /**
     * 消息的主体
     */
    private final byte[] body;

    /**
     * 事务的标志
     *
     * @see cn.me.alphamq.common.enumeration.TxMsgFlagEnum
     */
    private final int txFlag;

    /**
     * 事务的状态
     *
     * @see cn.me.alphamq.common.enumeration.LocalTxStateEnum
     */
    private final int transactionState;

    /**
     * 能够唯一标识生产者的 id
     */
    private final String producerId;

    /**
     * 事务消息的 id
     */
    private final String msgId;

    /**
     * 发送事务消息的通道的上下文
     */
    private final ChannelHandlerContext ctx;

    public TxMsgModel(PushTxMsgReq pushTxMsgReq, ChannelHandlerContext ctx) {
        this.topic = pushTxMsgReq.getTopic();
        this.queueId = pushTxMsgReq.getQueueId();
        this.body = pushTxMsgReq.getBody();
        this.txFlag = pushTxMsgReq.getTxFlag();
        this.transactionState = pushTxMsgReq.getTransactionState();
        this.producerId = pushTxMsgReq.getProducerId();
        this.msgId = pushTxMsgReq.getMsgId();
        this.ctx = ctx;
    }

    public String getTopic() {
        return topic;
    }

    public int getQueueId() {
        return queueId;
    }

    public byte[] getBody() {
        return body;
    }

    public int getTxFlag() {
        return txFlag;
    }

    public int getTransactionState() {
        return transactionState;
    }

    public String getProducerId() {
        return producerId;
    }

    public String getMsgId() {
        return msgId;
    }

    public ChannelHandlerContext getCtx() {
        return ctx;
    }
}
